package com.hundsun.yr.universal.p2p.bean;

import java.io.Serializable;

import android.content.Context;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.hundsun.yr.universal.library.utils.HsDateUtils;
import com.hundsun.yr.universal.library.utils.HsNumberUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.view.itemview.BasicItemViewH;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.p2p.config.Container;
import com.hundsun.mobile.zwgt.R;





/**
 * @Title: OrderEntity.java 
 * @Description: 订单详情
 * @date 2016-2-2 下午6:24:43 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class OrderEntity extends ResponseBean implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 实际支付金额
	 */
	private double actualAmount ;
	/**
	 * 投资类型 0-转让  TRANSFER("0","转让"),  1-受让  FARMIN("1","受让"),  2-投资 INVEST("2","投资")
	 */
	private String bizType ;
	/**
	 * 创建时间
	 */
	private String createTime ;
	/**
	 * 减免金额
	 */
	private double cutAmount;
	/**
	 * 优惠金额
	 */
	private double discountAmount;
	/**
	 * 费用 
	 */
	private double fee;
	/**
	 * 商品描述	
	 */
	private String goodsDesc;
	/**
	 * 产品id
	 */
	private String goodsId;
	/**
	 * 商品名称
	 */
	private String goodsName;
	/**
	 *投资金额  
	 */
	private double investAmnt;
	/**
	 * 投资份额
	 */
	private double investShare;
	/**
	 * 营销商品号
	 */
	private String mktGoodsId;
	/**
	 * 订单号
	 */
	private String orderNo;
	/**
	 * 应缴纳金额
	 */
	private double shouldPayAmount;
	/**
	 * 订单状态
	 */
	private String status ;
	/**
	 * 用户id
	 */
	private String userNo ;
	/**
	 * 订单持续时间
	 */
	private int payTimeLimit ;
	/**
	 * 开始支付时间
	 */
	private long startPayTime ;
	/**
	 * 转让ID
	 */
	private String transferId;
	
	public String getTransferId() {
		return transferId;
	}


	public void setTransferId(String transferId) {
		this.transferId = transferId;
	}


	public double getActualAmount() {
		return actualAmount;
	}


	public void setActualAmount(double actualAmount) {
		this.actualAmount = actualAmount;
	}


	public String getBizType() {
		return bizType;
	}


	public void setBizType(String bizType) {
		this.bizType = bizType;
	}


	public String getCreateTime() {
		return createTime;
	}


	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}


	public double getCutAmount() {
		return cutAmount;
	}


	public void setCutAmount(double cutAmount) {
		this.cutAmount = cutAmount;
	}


	public double getDiscountAmount() {
		return discountAmount;
	}


	public void setDiscountAmount(double discountAmount) {
		this.discountAmount = discountAmount;
	}


	public double getFee() {
		return fee;
	}


	public void setFee(double fee) {
		this.fee = fee;
	}


	public String getGoodsDesc() {
		return goodsDesc;
	}


	public void setGoodsDesc(String goodsDesc) {
		this.goodsDesc = goodsDesc;
	}


	public String getGoodsId() {
		return goodsId;
	}


	public void setGoodsId(String goodsId) {
		this.goodsId = goodsId;
	}


	public String getGoodsName() {
		return goodsName;
	}


	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}


	public double getInvestAmnt() {
		return investAmnt;
	}


	public void setInvestAmnt(double investAmnt) {
		this.investAmnt = investAmnt;
	}


	public double getInvestShare() {
		return investShare;
	}


	public void setInvestShare(double investShare) {
		this.investShare = investShare;
	}


	public String getMktGoodsId() {
		return mktGoodsId;
	}


	public void setMktGoodsId(String mktGoodsId) {
		this.mktGoodsId = mktGoodsId;
	}


	public String getOrderNo() {
		return orderNo;
	}


	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}


	public double getShouldPayAmount() {
		return shouldPayAmount;
	}


	public void setShouldPayAmount(double shouldPayAmount) {
		this.shouldPayAmount = shouldPayAmount;
	}


	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}


	public String getUserNo() {
		return userNo;
	}


	public void setUserNo(String userNo) {
		this.userNo = userNo;
	}


	public int getPayTimeLimit() {
		return payTimeLimit;
	}


	public void setPayTimeLimit(int payTimeLimit) {
		this.payTimeLimit = payTimeLimit;
	}


	public long getStartPayTime() {
		return startPayTime;
	}


	public void setStartPayTime(long startPayTime) {
		this.startPayTime = startPayTime;
	}


	/**
	 * 获取结束时间
	 * @param outTime
	 * @return
	 */
	public String getPayEndTime() {
		String endtime=MathUtils.plus(startPayTime,payTimeLimit*60000);
		return endtime;
	}
	
	/**
	 * 显示交易时间
	 * @return
	 */
	public String dispalyCreateTime(){
		String disTradeTime=HsDateUtils.timeformat(HsDateUtils.farmat_date_1, createTime);
		return disTradeTime;
	}
	

	/**
	 * 显示交易时间
	 * @return
	 */
	public String dispalyTradeTime(){
		String disTradeTime=HsDateUtils.timeformat(HsDateUtils.farmat_date_3, startPayTime);
		return disTradeTime;
	}

	/**
	 * 获取显示金额
	 * @return
	 */
	public String displayActualAmount(Context context){
		String money=context.getString(R.string._rmb,HsNumberUtils.moneyThousandsFormat(actualAmount));
		return money;
	}
	
	/**
	 * 显示交易类型
	 * @return
	 */
	public String dispalyBizType(){
		//交易类型
		String type = "";
		if(TextUtils.equals(bizType, "INVEST")){
			type="投资";
		}else if(TextUtils.equals(bizType, "FARMIN")){
			type="受让";
		}else if(TextUtils.equals(bizType, "TRANSFER")){
			type="转让";
		}
		
		return type;
	}
	
	/**
	 * 显示支付限制时间
	 * @return
	 */
	public String displayOutTime(Context context){
		String pay_outtime="";
		
		
		String today=HsDateUtils.getDay(Container.getInstance().getStringTime());
		String endday=HsDateUtils.getDay(getPayEndTime());
		if(TextUtils.equals(today, endday)){
			pay_outtime=context.getString(R.string._pay_outtime,HsDateUtils.timeformat(HsDateUtils.farmat_time_2, getPayEndTime()));
		}else{
			pay_outtime=context.getString(R.string._pay_outtime_1,HsDateUtils.timeformat("MM-dd HH:mm", getPayEndTime()));
		}
		
		return pay_outtime;
	}
	
	/**
	 * 显示支付开始时间
	 * @return
	 */
	public String displayStartTime(Context context){
		String pay_startTime="";
		
		pay_startTime=context.getString(R.string._pay_outtime_1,HsDateUtils.timeformat("MM-dd HH:mm", createTime));
		
		return pay_startTime;
	}
	
	
	
	/**
	 *  支付状态
	 * @param btn_pay 支付按钮
	 * @param toolbar_menu 取消按钮
	 * @param bv_remainingtime 剩余时间
	 */
	public void payStatus(HSButton btn_pay,TextView toolbar_menu,BasicItemViewH bv_remainingtime){
		
		if(MathUtils.compare(Container.getInstance().getStringTime(), getPayEndTime())<0){
			String lastTime=MathUtils.subtract(getPayEndTime(),Container.getInstance().getStringTime());
//		String thistime=System.currentTimeMillis()+10*1000+"";
//		if(MathUtils.compare(thistime, getPayEndTime())<0){
//	    	String lastTime=MathUtils.subtract(getPayEndTime(),thistime);
	    	btn_pay.setEnabled(true);
			toolbar_menu.setVisibility(View.VISIBLE);
			TimeCount mTimeCount=new TimeCount(MathUtils.string2long(lastTime), 1000,btn_pay,bv_remainingtime,toolbar_menu);
			mTimeCount.start();
	    }else{
	    	bv_remainingtime.getmSubTitle().setText(R.string.close_order);
			btn_pay.setEnabled(false);
			toolbar_menu.setVisibility(View.GONE);
	    }
	}
	
	
	
	/* 定义一个倒计时的内部类 */
	class TimeCount extends CountDownTimer {
		
		private HSButton btn_pay=null;
		private BasicItemViewH bv_remainingtime=null;
		private TextView toolbar_menu=null;
		public TimeCount(long millisInFuture, long countDownInterval,HSButton btn_pay,BasicItemViewH bv_remainingtime,TextView toolbar_menu) {
			super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
			this.bv_remainingtime=bv_remainingtime;
			this.btn_pay=btn_pay;
			this.toolbar_menu=toolbar_menu;
		}

		@Override
		public void onFinish() {// 计时完毕时触发
			bv_remainingtime.getmSubTitle().setText(R.string.close_order);
			btn_pay.setEnabled(false);
			toolbar_menu.setVisibility(View.GONE);
		}

		@Override
		public void onTick(long millisUntilFinished) {// 计时过程显示
			
			bv_remainingtime.getmSubTitle().setText(HsDateUtils.formatTime(millisUntilFinished));
		}
		
	}
	
}
